package org.spring.boot.rabbitmq.receive;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.boot.rabbitmq.conf.RabbitConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author: eastcom
 * @desc:
 **/
@Component
public class BookHandler {

	private static final Logger log = LoggerFactory.getLogger(BookHandler.class);

	@RabbitListener(queues = {RabbitConfig.REGISTER_QUEUE_NAME})
	public void listenerDelayQueue(String book, Message message, Channel channel) {
		log.info("[listenerDelayQueue 监听的消息] - [{}]",  book);
		try {
			// TODO 通知 MQ 消息已被成功消费,可以ACK了
			channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		} catch (IOException e) {
			// TODO 如果报错了,那么我们可以进行容错处理,比如转移当前消息进入其它队列
		}
	}
}
